Skip to content

Commit

Permalink
Update code to use new github archive URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
Seldaek committed Nov 4, 2012
1 parent 0878c6d commit 1682532
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 9 deletions.
9 changes: 8 additions & 1 deletion src/Composer/Downloader/ArchiveDownloader.php
Expand Up @@ -87,14 +87,21 @@ protected function getFileName(PackageInterface $package, $path)
*/
protected function processUrl(PackageInterface $package, $url)
{
// support for legacy github archives
if ($package->getDistReference() && preg_match('{^https?://(?:www\.)?github\.com/([^/]+)/([^/]+)/(zip|tar)ball/(.+)$}i', $url, $match)) {
$url = 'https://github.com/' . $match[1] . '/'. $match[2] . '/' . $match[3] . 'ball/' . $package->getDistReference();
}

if ($package->getDistReference() && preg_match('{^https?://(?:www\.)?github\.com/([^/]+)/([^/]+)/archive/.+\.(zip|tar\.gz)$}i', $url, $match)) {
$url = 'https://github.com/' . $match[1] . '/'. $match[2] . '/archive/' . $package->getDistReference() . '.' . $match[3];
}

if (!extension_loaded('openssl') && (0 === strpos($url, 'https:') || 0 === strpos($url, 'http://github.com'))) {
// bypass https for github if openssl is disabled
if (preg_match('{^https?://github.com/([^/]+/[^/]+)/(zip|tar)ball/([^/]+)$}i', $url, $match)) {
$url = 'http://nodeload.github.com/'.$match[1].'/legacy.'.$match[2].'/'.$match[3];
$url = 'http://nodeload.github.com/'.$match[1].'/'.$match[2].'/'.$match[3];
} elseif (preg_match('{^https?://github.com/([^/]+/[^/]+)/archive/([^/]+)\.(zip|tar\.gz)$}i', $url, $match)) {
$url = 'http://nodeload.github.com/'.$match[1].'/'.$match[3].'/'.$match[2];
} else {
throw new \RuntimeException('You must enable the openssl extension to download files via https');
}
Expand Down
2 changes: 1 addition & 1 deletion src/Composer/Repository/Vcs/GitHubDriver.php
Expand Up @@ -108,7 +108,7 @@ public function getDist($identifier)
return $this->gitDriver->getDist($identifier);
}
$label = array_search($identifier, $this->getTags()) ?: $identifier;
$url = 'https://github.com/'.$this->owner.'/'.$this->repository.'/zipball/'.$label;
$url = 'https://github.com/'.$this->owner.'/'.$this->repository.'/archive/'.$label.'.zip';

return array('type' => 'zip', 'url' => $url, 'reference' => $label, 'shasum' => '');
}
Expand Down
18 changes: 17 additions & 1 deletion tests/Composer/Test/Downloader/ArchiveDownloaderTest.php
Expand Up @@ -43,7 +43,23 @@ public function testProcessUrl()
if (extension_loaded('openssl')) {
$this->assertEquals($expected, $url);
} else {
$this->assertEquals('http://nodeload.github.com/composer/composer/legacy.zip/master', $url);
$this->assertEquals('http://nodeload.github.com/composer/composer/zip/master', $url);
}
}

public function testProcessUrl2()
{
$downloader = $this->getMockForAbstractClass('Composer\Downloader\ArchiveDownloader', array($this->getMock('Composer\IO\IOInterface'), $this->getMock('Composer\Config')));
$method = new \ReflectionMethod($downloader, 'processUrl');
$method->setAccessible(true);

$expected = 'https://github.com/composer/composer/archive/master.tar.gz';
$url = $method->invoke($downloader, $this->getMock('Composer\Package\PackageInterface'), $expected);

if (extension_loaded('openssl')) {
$this->assertEquals($expected, $url);
} else {
$this->assertEquals('http://nodeload.github.com/composer/composer/tar.gz/master', $url);
}
}
}
12 changes: 6 additions & 6 deletions tests/Composer/Test/Repository/Vcs/GitHubDriverTest.php
Expand Up @@ -97,7 +97,7 @@ public function testPrivateRepository()

$dist = $gitHubDriver->getDist($identifier);
$this->assertEquals('zip', $dist['type']);
$this->assertEquals('https://github.com/composer/packagist/zipball/v0.0.0', $dist['url']);
$this->assertEquals('https://github.com/composer/packagist/archive/v0.0.0.zip', $dist['url']);
$this->assertEquals('v0.0.0', $dist['reference']);

$source = $gitHubDriver->getSource($identifier);
Expand All @@ -107,7 +107,7 @@ public function testPrivateRepository()

$dist = $gitHubDriver->getDist($sha);
$this->assertEquals('zip', $dist['type']);
$this->assertEquals('https://github.com/composer/packagist/zipball/v0.0.0', $dist['url']);
$this->assertEquals('https://github.com/composer/packagist/archive/v0.0.0.zip', $dist['url']);
$this->assertEquals('v0.0.0', $dist['reference']);

$source = $gitHubDriver->getSource($sha);
Expand Down Expand Up @@ -149,7 +149,7 @@ public function testPublicRepository()

$dist = $gitHubDriver->getDist($identifier);
$this->assertEquals('zip', $dist['type']);
$this->assertEquals('https://github.com/composer/packagist/zipball/v0.0.0', $dist['url']);
$this->assertEquals('https://github.com/composer/packagist/archive/v0.0.0.zip', $dist['url']);
$this->assertEquals($identifier, $dist['reference']);

$source = $gitHubDriver->getSource($identifier);
Expand All @@ -159,7 +159,7 @@ public function testPublicRepository()

$dist = $gitHubDriver->getDist($sha);
$this->assertEquals('zip', $dist['type']);
$this->assertEquals('https://github.com/composer/packagist/zipball/v0.0.0', $dist['url']);
$this->assertEquals('https://github.com/composer/packagist/archive/v0.0.0.zip', $dist['url']);
$this->assertEquals($identifier, $dist['reference']);

$source = $gitHubDriver->getSource($sha);
Expand Down Expand Up @@ -211,7 +211,7 @@ public function testPublicRepository2()

$dist = $gitHubDriver->getDist($identifier);
$this->assertEquals('zip', $dist['type']);
$this->assertEquals('https://github.com/composer/packagist/zipball/feature/3.2-foo', $dist['url']);
$this->assertEquals('https://github.com/composer/packagist/archive/feature/3.2-foo.zip', $dist['url']);
$this->assertEquals($identifier, $dist['reference']);

$source = $gitHubDriver->getSource($identifier);
Expand All @@ -221,7 +221,7 @@ public function testPublicRepository2()

$dist = $gitHubDriver->getDist($sha);
$this->assertEquals('zip', $dist['type']);
$this->assertEquals('https://github.com/composer/packagist/zipball/feature/3.2-foo', $dist['url']);
$this->assertEquals('https://github.com/composer/packagist/archive/feature/3.2-foo.zip', $dist['url']);
$this->assertEquals($identifier, $dist['reference']);

$source = $gitHubDriver->getSource($sha);
Expand Down

0 comments on commit 1682532

Please sign in to comment.